const pako = (window as any).pako;
export function onDatas(blob: any) {
    return new Promise(resolve=>{
        if(typeof blob == "string"){
            resolve(blob);
            return;
        }
        // console.log(blob);
        // 创建一个FileReader对象
        let reader = new FileReader();
    
        // 读取Blob对象
        reader.onload = function () {
            // 获取Blob对象中的数据
            let data = reader.result as any;
            // window.wsdata = data;
            // 将数据转换为字符串
            let str = String.fromCharCode.apply(null, new Uint8Array(data));
            // 将base64编码的数据解码为二进制数据
            const binaryData = atob(str);
    
            // 将二进制数据转换为Uint8Array
            const uint8Array = new Uint8Array(binaryData.length);
            for (let i = 0; i < binaryData.length; i++) {
                uint8Array[i] = binaryData.charCodeAt(i);
            }
    
            // 解压缩gzip数据
            const decompressedData = pako.inflate(uint8Array, { to: "string" });
    
            // console.log(decompressedData); // 输出解压缩后的数据
            resolve(decompressedData);
    
            // //var wsdata = pako.ungzip(str, {to: \"string\"});
            // // 解析为JSON对象
            // //let json = JSON.parse(str);
    
            // console.log(str); // 输出解析后的JSON对象
        };
        //var wsdata = pako.ungzip(ev.data, {to: \"string\"});
        reader.readAsArrayBuffer(blob);
        //console.warn(ev)
        // if (!_this.recvPause) {
        // 	var data = ev.data;
    
        // 	if (_this.recvClean) _this.messageData = [];
        // 	_this.writeNews(0, data);
        // }
    })
	
}
